package com.pe1n.yangtaopai.modle;

import com.pe1n.yangtaopai.bean.IntemOneListBean;

import com.pe1n.yangtaopai.retrofitApi.RetrofitApi;
import com.pe1n.yangtaopai.utils.OkHttp3Utils;
import com.pe1n.yangtaopai.utils.URLConstant;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * Created by Administrator on 2016/11/25.
 */

public class ModeIntemOne implements IModeIntemOne{
    private RetrofitApi retrofitapi=null;
    @Override
    public Observable<IntemOneListBean> getIntemOneListBean(String urlString) {
        initRetrofit();
        return retrofitapi.getIntemOneListBean(urlString);
    }

    private void initRetrofit() {
        OkHttpClient client = OkHttp3Utils.getOkHttpSingletonInstance();
        //Log.i(TAG, "---->initRetrofit: " + client.toString());
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(URLConstant.BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                // Retrofit2+RxJava实现网络访问，必须设置以下选项。
                // RxJavaCallAdapterFactory就是把Call转换成Observable.
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        retrofitapi = retrofit.create(RetrofitApi.class);

    }
}
